package com.ruoyi.bizsys.service.impl;

import java.math.BigDecimal;
import java.util.List;
import java.util.Arrays;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.RiskConstants;
import com.ruoyi.common.utils.DateUtils;
            import org.springframework.stereotype.Service;
    import com.ruoyi.bizsys.mapper.CustActiveIncreaseLogMapper;
import com.ruoyi.bizsys.domain.CustActiveIncreaseLog;
import com.ruoyi.bizsys.service.ICustActiveIncreaseLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;


/**
 * 主动提额日志Service业务层处理
 *
 * @author african-loan
 * @date 2022-03-31
 */
@Service
public class CustActiveIncreaseLogServiceImpl extends ServiceImpl<CustActiveIncreaseLogMapper,CustActiveIncreaseLog> implements ICustActiveIncreaseLogService {

    /**
     * 查询主动提额日志
     *
     * @param id 主动提额日志ID
     * @return 主动提额日志
     */
    @Override
    public CustActiveIncreaseLog selectCustActiveIncreaseLogById(Long id) {
        return this.getById(id);
    }

    /**
     * 查询主动提额日志列表
     *
     * @param custActiveIncreaseLog 主动提额日志
     * @return 主动提额日志
     */
    @Override
    public List<CustActiveIncreaseLog> selectCustActiveIncreaseLogList(CustActiveIncreaseLog custActiveIncreaseLog) {
        return this.list(new QueryWrapper<>(custActiveIncreaseLog).last("order by id desc"));
    }

    /**
     * 新增主动提额日志
     *
     * @param custActiveIncreaseLog 主动提额日志
     * @return 结果
     */
            @Override
    public int insertCustActiveIncreaseLog(CustActiveIncreaseLog custActiveIncreaseLog) {
                                                                                                                                                                                                    custActiveIncreaseLog.setCreateTime(DateUtils.getNowDate());
                                                                    return baseMapper.insert(custActiveIncreaseLog);
    }

    /**
     * 修改主动提额日志
     *
     * @param custActiveIncreaseLog 主动提额日志
     * @return 结果
     */
            @Override
    public int updateCustActiveIncreaseLog(CustActiveIncreaseLog custActiveIncreaseLog) {
                                                                                                                                                                                                                                            custActiveIncreaseLog.setUpdateTime(DateUtils.getNowDate());
                            return baseMapper.updateById(custActiveIncreaseLog);
    }

    /**
     * 批量删除主动提额日志
     *
     * @param ids 需要删除的主动提额日志ID
     * @return 结果
     */
            @Override
    public int deleteCustActiveIncreaseLogByIds(Long[] ids) {
        return baseMapper.deleteBatchIds(Arrays.asList(ids));
    }

    /**
     * 删除主动提额日志信息
     *
     * @param id 主动提额日志ID
     * @return 结果
     */
    @Override
    public int deleteCustActiveIncreaseLogById(Long id) {
        return baseMapper.deleteById(id);
    }

    @Override
    public boolean saveLog(String customerNo, String ruleType, JSONObject resJson) {
        CustActiveIncreaseLog log = new CustActiveIncreaseLog();
        log.setCustNo(customerNo);
        log.setIncreaseType(ruleType);
        String ruleResult = resJson.getString(RiskConstants.RULE_RESULT_DEAL_TYPE_KEY);
        BigDecimal adjustLimit = resJson.getBigDecimal(RiskConstants.RULE_RAISE_PASS_ADJUST_LIMIT);
        log.setIncreasedAmt(adjustLimit);
        log.setRiskResult(ruleResult);
        return this.save(log);
    }



}
